package com.matrix.rabbitmqtest.direct;

import cn.hutool.core.lang.Console;
import com.matrix.rabbitmqtest.util.AppKeys;
import com.matrix.rabbitmqtest.util.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * direct交换机
 */
public class Producer {
    public static void main(String[] args) throws IOException {
        Channel channel = RabbitMQUtil.getChannel();
        channel.exchangeDeclare(AppKeys.DIRECT_EXCHANGE, BuiltinExchangeType.DIRECT);
        while (true) {
            String str = Console.input(); // 输入error,warning或info
            channel.basicPublish(AppKeys.DIRECT_EXCHANGE, "/" + str, null, ("***" + str + "***").getBytes(StandardCharsets.UTF_8));
        }
    }
}
